﻿package yii.base{

	import flash.utils.*;

	public class CModel extends CComponent{


	private var _errors:Array=new Array();	// attribute name => array of errors
	private var _validators;  		// validators
	private var _scenario:String='';  	// scenario




	/**
	 * Returns a list of behaviors that this model should behave as+
	 * The return value should be an array of behavior configurations indexed by
	 * behavior names+ Each behavior configuration can be either a string specifying
	 * the behavior class or an array of the following structure:
	 * <pre>
	 * 'behaviorName'=>array(
	 *     'class'=>'path+to+BehaviorClass',
	 *     'property1'=>'value1',
	 *     'property2'=>'value2',
	 * )
	 * </pre>
	 *
	 * Note, the behavior classes must implement {@link IBehavior} or extend from
	 * {@link CBehavior}+ Behaviors declared in this method will be attached
	 * to the model when it is instantiated+
	 *
	 * For more details about behaviors, see {@link CComponent}+
	 * @return array the behavior configurations (behavior name=>behavior configuration)
	 * @since 1+0+2
	 */
	public function behaviors():Array{
		return new Array();
	}




	/**
	 * This method is invoked after a model instance is created by new operator+
	 * The default implementation raises the {@link onAfterConstruct} event+
	 * You may override this method to do postprocessing after model creation+
	 * Make sure you call the parent implementation so that the event is raised properly+
	 */
	protected function afterConstruct():void{
		//trace( "afterConstructは未実装です。" );
//		if(this.hasEventHandler('onAfterConstruct'))
//			this.onAfterConstruct(new CEvent(this));
	}



	/**
	 * Sets the scenario for the model+
	 * @param string $value the scenario that this model is in+
	 * @see getScenario
	 * @since 1+0+4
	 */
	public function setScenario($value:String):void{
		this._scenario=$value;
	}




	/**
	 * Performs the validation+
	 *
	 * This method executes the validation rules as declared in {@link rules}+
	 * Only the rules applicable to the current {@link scenario} will be executed+
	 * A rule is considered applicable to a scenario if its 'on' option is not set
	 * or contains the scenario+
	 *
	 * Errors found during the validation can be retrieved via {@link getErrors}+
	 *
	 * @param array $attributes list of attributes that should be validated+ Defaults to null,
	 * meaning any attribute listed in the applicable validation rules should be
	 * validated+ If this parameter is given as a list of attributes, only
	 * the listed attributes will be validated+
	 * @param boolean $clearErrors whether to call {@link clearErrors} before performing validation
	 * @return boolean whether the validation is successful without any error+
	 * @see beforeValidate
	 * @see afterValidate
	 */
	public function validate($attributes:Array=null, $clearErrors:Boolean=true):Boolean{
		return true;
//		if($clearErrors)
//			this.clearErrors();
//		if(this.beforeValidate())
//		{
//			foreach(this.getValidators() as $validator)
//				$validator.validate(this,$attributes);
//			this.afterValidate();
//			return !this.hasErrors();
//		}
//		else
//			return false;
	}


























	}
}